﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Yugi.Client.Card.Load
{
    public class LoadCardData : ILoad
    {
        #region ILoad Members

        public event EventHandler Complete;

        public bool IsParallel
        {
            get { return false; }
        }

        public void Load(object state)
        {
            string root_path = PathManager.DataRoot;
            DirectoryInfo root = new DirectoryInfo(root_path);
            FileDecoder.YFileDecoder decoder = new Yugi.Client.Card.FileDecoder.YFileDecoder();
            YBaseCard card;
            int id=1;
            
            foreach (FileInfo item in root.GetFiles())
            {
                if (item.Extension == ".bin")
                {
                    try
                    {
                        string name = item.FullName.Split('.')[0];
                        card = decoder.BinaryFileDecoderCard(name + ".bin");
                        card.Card_TypeID = id;
            
                        CardManager.addCard(card, id++);
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }
            }
            if (Complete != null)
                Complete(this, new EventArgs());
        }

        #endregion

    }
}
